package com.yunxin.admin.system.application.assembler;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yunxin.admin.system.application.command.AddRoleCommand;
import com.yunxin.admin.system.application.command.UpdateRoleCommand;
import com.yunxin.admin.system.application.dto.OptionDTO;
import com.yunxin.admin.system.application.dto.RoleInfoDTO;
import com.yunxin.admin.system.application.dto.RolePageDTO;
import com.yunxin.admin.system.domain.model.role.Role;
import com.yunxin.admin.system.infra.persistence.entity.SysRoleDO;
import org.mapstruct.InheritInverseConfiguration;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;

import java.util.List;

/**
 * 角色对象转换器
 *
 * @author zero°
 * @since 2023-05-22
 */
@Mapper(componentModel = "spring")
public interface RoleAssembler {
    /**
     * entity 转 dto
     * @param page page
     * @return Page<RolePageDTO>
     */
    Page<RolePageDTO> toRolePageDTO(Page<SysRoleDO> page);
    /**
     * entity 转 dto
     * @param entity entity
     * @return RoleInfoDTO
     */
    RoleInfoDTO toRoleInfoDTO(SysRoleDO entity);


    @Mapping(target = "value", source = "id")
    @Mapping(target = "label", source = "name")
    OptionDTO<Long> entity2Option(SysRoleDO role);

    /**
     * entity 转 dto
     * @param roles roles
     * @return List<AdminOptionDTO<Long>>
     */
    @Mapping(target = "value", source = "id")
    @Mapping(target = "label", source = "name")
    List<OptionDTO<Long>> toOptionDTOList(List<SysRoleDO> roles);
    /**
     * command 转 entity
     * @param command command
     * @return SysDictType
     */
    Role formAddRoleCommand(AddRoleCommand command);
    /**
     * command 转 entity
     * @param command command
     * @return SysDictType
     */
    @InheritInverseConfiguration(name="toRoleInfoDTO")
    Role formUpdateRoleCommand(UpdateRoleCommand command);

}